package mfuny.ggongal.admin.https;

import java.util.HashMap;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
//import org.ow2.util.base64.Base64;

class Neutral {
	private String[] ope2h = new String[] { "bfsuXJ4K", "fNUDbd1i", "qplwiUYZ",
			"fiyXMXsa", "Hz1eh9qv", "fMhHS0gV", "Txt3XiOJ", "AKnxyLui",
			"p0dz2z71", "fBJYQWZy", "9QnqCl8A", "cSzREE1k", "T8x9Uq0S",
			"kR1YOlkW", "rMN2obty", "sA9PUZdQ", "4LjENlsX", "Y9MBlW9D",
			"XX3FPEkf", "vtQnW3t0", "Kyifv0yR", "9ktmYAvk", "8c6EgJ1T",
			"ROBxMhKk", "ACAtObDA", "m5t7zdzd", "6U9cxoOJ", "cDnDZTVV",
			"auCdOd0r", "fExNU0AT", "yBfbRtiv", "t67NNArR", "tpAZpxYi",
			"9OoAxKfg", "CMkV1X2i", "de5ADInH", "pGYv8y10", "bgJeVDcP",
			"e1qsNupD", "7Kn4Ovru", "OrrsaOq5", "j3eGL3Wd", "Ch5TC5GL",
			"ReF1xBAS", "tASwFjTF", "Vn6RBSKT", "2r73u6wf", "9vklbWBp",
			"C2MFh7BG", "rBEQHR7a", "OgBsazrL", "6hyRGI1f", "u7OIXgsj",
			"iwaa8ffv", "Am0oxyQb", "M45dkKpZ", "giE5ZOyH", "8Ubs8NSX",
			"QzJpmXZR", "3lNbJ1HS", "aa5QhiYP", "ifLdKTiZ", "FwOV6yve",
			"DSR41sV3", "SEnYWfKN", "rNcZB1Lq", "IwR9c8SF", "oqWtpZ7k",
			"9pNZ366c", "BMXG7pXH", "Axhhn4rp", "0DNgOQAX", "KBwAGlXP",
			"h1K9MVOr", "dEMRp1r3", "Ia0LX7cO", "uQHOfOGG", "WE05MkE7",
			"Gy1sWUm0", "p6ZguBdM", "JnMhYl82", "K5u4SFla", "gpFCKdFk",
			"YyjKyK8j", "Xw7ILDO0", "roeWvW46", "CUuW8ozO", "QCePq3Ts",
			"FtQJdmpa", "DICo60Ua", "oGWAzFci", "QvrZCzkM", "y9SUUxzu",
			"99TQKO6Y", "SMNRBZXe", "hS650KQX", "Oum2W8SB", "OFJw0Ncz",
			"6zba4j8v", "dB81mqkg" };
	
	
	// 임시 비번 가져오기.
	protected String[] getOpe2h() {
		return ope2h;
	}
	
	// 글자 뒤집기.
	protected String ternOver(String value) {
		char[] c = value.toCharArray();
		char[] result = new char[c.length];

		for (int i = c.length; i > 0; i--) {
			result[i - 1] = c[c.length - i];
		}

		return String.valueOf(result);
	}
	
	
	// 사이사이 글자넣기.
	protected String insertStr(String main, String target) {
		if(main.length() < 12 ) {
			return "sss|||" + target + main; 
		}
		if (target.length() > 10) {
			target = target.substring(0, 10);
		}

		StringBuffer sb = new StringBuffer(main);
		for (int i = 0, j = 0; i < sb.length() + target.length(); i++) {
			if (i % 2 == 1 && j < target.length()) {
				sb.insert(i, target.substring(j, j + 1));
				j++;
			}
		}

		return sb.toString();
	}
	
	//맨 뒤 두 글자 순서 바꾸기.
	protected String lastTurnOver(String bStr) {
		StringBuffer sb = new StringBuffer(bStr);
		String firstChar = sb.substring(0, 1);
		sb = sb.deleteCharAt(0);
		String lastChar = sb.substring(sb.length() - 1);
		sb = sb.deleteCharAt(sb.length() - 1);
		sb.insert(0, lastChar);
		sb.append(firstChar);
		
		return sb.toString();
	}
	
	//사이사이 글자빼기.
	protected HashMap<String, Object> separateStr(String main) {
		HashMap<String, Object> resultMap = new HashMap<String, Object>();
		StringBuffer sb = new StringBuffer(main);
		if(main.indexOf("sss|||") > -1) {
			main = main.replace("sss|||", "");
			resultMap.put("pin", main.substring(0, 10));
			resultMap.put("main", main.substring(10));
		} else {
			String pin = "";
			for(int i = 0, j = 0; i < 20; i++ ) {
				if( i % 2 == 1 ) {
					pin += main.substring(i, i + 1);
					sb = sb.deleteCharAt(i - j);
					j++;
				}
			}
			resultMap.put("pin", pin);
			resultMap.put("main", sb.toString());
		}
		
		return resultMap;
	}
	
	
	// 임시 비번 생성기.
	protected String shufflePasswd(int len) {
		char[] charSet = new char[] { '0', '1', '2', '3', '4', '5', '6', '7',
				'8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
				'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
				'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
				'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
				'U', 'V', 'W', 'X', 'Y', 'Z' };
		int idx = 0;
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < len; i++) {
			idx = (int) (charSet.length * Math.random());
			sb.append(charSet[idx]);
		}
		return sb.toString();
	}
	
	
	// 인코딩.
	protected String change(String jsonStr) {
		return new BASE64Encoder().encode(jsonStr.getBytes());
	}
	
	
	// 디코딩.
	protected String rollback(byte[] bStr) throws Exception {
		return new String(new BASE64Decoder().decodeBuffer(new String(bStr)));
	}
	protected String rollback(String bStr) throws Exception {
		return new String(new BASE64Decoder().decodeBuffer(bStr));
	}
	
	
	public static void main(String[] args) throws Exception {
		String a = "eyJpZCI6ImhrcGFyayIsInJlYXNvbiI6Iu2VnOq4gCDthYzsiqTtirggMTIzNCBhYmNkIiwidGFnIjoidXNlcl9hZGRHZ29uZyIsImdnb25nIjotNTAwfQ==";
		System.out.println(new Neutral().rollback(a));
	}
}
